package demo1;

class Solution {
    public static int removeElement(int[] nums, int val) {
        int count = 0;
        for(int i=0; i<nums.length-count; i++) {
            if(nums[i] == val) {
                for(int j=i;j<nums.length-1;j++){
                    nums[j] = nums[j+1];
                }
                if(i!=nums.length-1){
                    i--;
                }
            }else{
                count++;
            }
        }
        return count;

    }
}

public class Test {
    public static void main(String[] args) {
        MyArraylist myArraylist = new MyArraylist();
        myArraylist.add(1);
        myArraylist.add(2);
        myArraylist.add(3);
        myArraylist.add(4);
        myArraylist.add(5);
        myArraylist.add(6);
        myArraylist.display();
        System.out.println("===========");
        myArraylist.add(2,10);
        myArraylist.display();
        myArraylist.remove(5);
        myArraylist.display();
        int ret = myArraylist.get(2);
        System.out.println(ret);
        myArraylist.clear();
        myArraylist.display();
    }
    public static void main1(String[] args) {
        int[] arr = {0,1,2,2,3,0,4,2};
        Solution.removeElement(arr,2);
    }
}
